package cn.tedu.ivos.geofence.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceQuery;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceSaveParam;
import cn.tedu.ivos.geofence.pojo.vo.GeofenceVO;
import cn.tedu.ivos.geofence.service.GeofenceService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/geofence/")
@Slf4j
@Tag(name = "围栏模块")
public class GeofenceController {
    @Autowired
    GeofenceService  geofenceService;

    @GetMapping("select")
    @Operation(summary = "查询电子围栏")
    @ApiOperationSupport(order = 10)
    public JsonResult selectGeo(GeofenceQuery query){
        log.debug("查询电子围栏业务 query{}", query);
        List<GeofenceVO> list= geofenceService.selectGeo(query);
        return JsonResult.ok(list);
    }

    @PostMapping("save")
    @Operation(summary = "保存电子围栏")
    @ApiOperationSupport(order = 20)
    public JsonResult saveGeo(@Validated GeofenceSaveParam geo){
        log.debug("保存电子围栏业务 geo{}", geo);
        geofenceService.saveGeo(geo);
        return JsonResult.ok();
    }

    @PostMapping("changeStatus/{id}/{status}")
    @Operation(summary = "更新电子围栏状态")
    @ApiOperationSupport(order = 30)
    public JsonResult changeStatus(@PathVariable("id") Long id, @PathVariable("status") String status){
        log.debug("更新电子围栏状态业务 id{}, status{}", id, status);
        GeofenceSaveParam  geo = new GeofenceSaveParam();
        geo.setId(id);
        geo.setStatus(status);
        geofenceService.saveGeo(geo);
        return JsonResult.ok();
    }

    @GetMapping("delete")
    @Operation(summary = "删除电子围栏")
    @ApiOperationSupport(order = 40)
    public JsonResult deleteGeo(Long id){
        log.debug("删除电子围栏业务 id{}", id);
        geofenceService.deleteGeo(id);
        return JsonResult.ok();
    }
}
